﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Antix.Data.Objects
{
    /// <summary>
    /// <para>Table Attribute</para>
    /// <para>Defines the table held for a data enabled class</para>
    /// </summary>
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface, AllowMultiple = false)]
    public class DataTableAttribute : Attribute
    {
        #region Constructors etc.

        /// <summary>
        /// <para>Create a Table attribute</para>
        /// </summary>
        public DataTableAttribute(string name)
        {
            _Name = name;
            _Schema = "dbo";
        }

        /// <summary>
        /// <para>Create a Table attribute</para>
        /// </summary>
        public DataTableAttribute(Type type)
            : this(type.Name) { }

        #endregion

        #region Properties

        #region Name

        private string _Name = null;

        /// <summary>
        /// <para>Override for the name of the table in the database</para>
        /// </summary>
        public string Name
        {
            get { return _Name; }
            set { _Name = value; }
        }

        private string _NameOriginal;

        /// <summary>
        /// <para>NameOriginal for this table</para>
        /// </summary>
        public string NameOriginal
        {
            get { return _NameOriginal == null ? _Name : _NameOriginal; }
            set { _NameOriginal = value; }
        }

        #endregion

        #region Schema

        private string _Schema;

        /// <summary>
        /// <para>Schema for this table</para>
        /// </summary>
        public string Schema
        {
            get { return _Schema; }
            set { _Schema = value; }
        }

        private string _SchemaOriginal;

        /// <summary>
        /// <para>SchemaOriginal for this table</para>
        /// </summary>
        public string SchemaOriginal
        {
            get { return _SchemaOriginal == null ? _Schema : _SchemaOriginal; }
            set { _SchemaOriginal = value; }
        }

        #endregion

        #endregion

        #region Methods

        #region GetFullName

        /// <summary>
        /// <para>Get the full name of the table [Schema].[Table]</para>
        /// </summary>
        public string GetFullName()
        {
            return "[" + this.Schema + "].[" + this.Name + "]";
        }

        /// <summary>
        /// <para>Get the original full name of the table [Schema].[Table]</para>
        /// </summary>
        public string GetFullNameOriginal()
        {
            return "[" + this.SchemaOriginal + "].[" + this.NameOriginal + "]";
        }

        #endregion

        #endregion
    }
}
